﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoogleMapsApiWebServices.Core;

namespace GoogleMapsApiWebServices.Elevation
{
    public class ElevationRequest : MapsApiRequest
    {
        protected override string BaseUri { get { return @"http://maps.googleapis.com/maps/api/elevation"; } }

        [QueryStringParameter(IsRequired = false, QueryStringParameter = "locations", CollectionSeparator = '|')]
        public IList<Coordinate> Locations { get; set; }

        [QueryStringParameter(IsRequired = false, QueryStringParameter = "path", CollectionSeparator = '|')]
        public IList<Coordinate> Path { get; set; }

        [QueryStringParameter(IsRequired = false, QueryStringParameter = "samples")]
        public int Samples { get; set; }

        protected override void ValidateRequest()
        {
            if (Path != null && Path.Count < 2)
                throw new ValidationException("Path must contain at least 2 Locations");

            if ((Locations == null && Path == null)
                || (Locations != null && Locations.Count == 0 && Path == null)
                || (Path != null && Path.Count < 2 && Locations == null)
                || (Path != null && Path.Count < 2 && Locations != null && Locations.Count == 0)
                )
            {
                throw new ValidationException();
            }
        }
    }
}
